package com.sd.activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.sd.activity.r.R;
import com.sd.util.FirstDo;
import com.sd.util.PreferencesManager;

/**
 * 启动界面
 * 
 * 1.判断是否是第一次登陆
 * 
 * @author Alex.Lu
 * 
 */
public class LoaderActivity extends BaseActivity implements Runnable {

	private TextView mLoadhintTV;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_loader);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		mLoadhintTV = (TextView)findViewById(R.id.loadhint);
		Thread thread = new Thread(this);
		thread.start();
		
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		boolean isFirst = PreferencesManager.getInstance().getISFirst();
		if (isFirst) {
			FirstDo f = new FirstDo();
			f.start(this,hander);
			intent.setClass(this, GuideActivity.class);
		}else{
			intent.setClass(this, MainTabActivity.class);
		}
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		startActivity(intent);
		finish();
		
	}
	
	
	Handler hander = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.what) {
			case 1:
				mLoadhintTV.setText(LoaderActivity.this.getResources().getString(R.string.msg_loader_copy));
				break;
			case 2:
				mLoadhintTV.setText(LoaderActivity.this.getResources().getString(R.string.msg_loader_unzip));
				break;
			case 3:
				mLoadhintTV.setText(LoaderActivity.this.getResources().getString(R.string.msg_loader_init));
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
		
	};

}